package org.jeewx.api.core.req.model.message;

import java.util.Iterator;
import java.util.Map;

import org.jeewx.api.core.annotation.ReqType;
import org.jeewx.api.core.req.model.WeixinReqParam;

import net.sf.json.JSONObject;

/**
 * 取多媒体文件
 * 
 * @author sfli.sir
 * 
 */
public class TemplateMessageSendResult {


	private String touser;
	
	private String template_id;
	
	private String url;
	
	private Map<String,TemplateData> data;

	public String getTouser() {
		return touser;
	}

	public void setTouser(String touser) {
		this.touser = touser;
	}

	public String getTemplate_id() {
		return template_id;
	}

	public void setTemplate_id(String template_id) {
		this.template_id = template_id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Map<String, TemplateData> getData() {
		return data;
	}

	public void setData(Map<String, TemplateData> data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "TemplateMessageSendResult [touser=" + touser + ", template_id=" + template_id + ", url=" + url
				+ ", data=" + data + "]";
	}
	
	public  com.alibaba.fastjson.JSONObject toJSON() {
		com.alibaba.fastjson.JSONObject result = new  com.alibaba.fastjson.JSONObject();
		result.put("touser", touser);
		result.put("template_id", template_id);
		result.put("url", url);
		com.alibaba.fastjson.JSONObject dataJson = new com.alibaba.fastjson.JSONObject();		
		if (data != null && data.size() > 0) {
			Iterator iter1 = data.keySet().iterator();
			while (iter1.hasNext()) {
				String key = (String) iter1.next();
				TemplateData temp = data.get(key);
				com.alibaba.fastjson.JSONObject tempalteJson = new com.alibaba.fastjson.JSONObject();
				tempalteJson.put("color", temp.getColor());
				tempalteJson.put("value", temp.getValue());
				dataJson.put(key, tempalteJson);
			}
		}
		result.put("data", dataJson);
		
		return result;
	}

}
